package com.xxxy.dongyexuan.mapper;


import com.xxxy.dongyexuan.po.User;
import org.apache.ibatis.annotations.*;
import org.mybatis.spring.annotation.MapperScan;

import java.util.List;

@MapperScan("com.xxxy.dongyexuan.demobeautyhaird.mapper")
public interface IUserMapper {

    @Select("select count(*) from user")
    public int getcount();

    @Select("SELECT * FROM user WHERE uname = #{uname} and upassword = #{upassword}")
    public User findUserByUsernameAndPassword(@Param("uname") String uname, @Param("upassword") String upassword);

    @Select("SELECT * FROM user WHERE uid = #{uid}")
    public User findById(@Param("uid") int uid);

    @Select("SELECT * FROM user")
    public List<User> findAll();

    @Select("SELECT * FROM user WHERE role = 1 LIMIT #{from}, #{pagesize}")
    public List<User> findVipUserAll(@Param("from") int from, @Param("pagesize") int pagesize);

    @Select("SELECT count(*) FROM user WHERE role = 1")
    public int getVipCount();

    @Insert("INSERT user VALUES (#{uid}, #{uname},#{urealname},#{upassword},#{usex},#{uage},#{uphone},#{role})")
    public int save(User user);

    @Update("UPDATE user SET uname = #{uname}, urealname=#{urealname},upassword = #{upassword},usex=#{usex},uage=#{uage},uphone=#{uphone},role=#{role} WHERE uid = #{uid}")
    public int merge(User user);

    @Delete("DELETE FROM user WHERE uid = #{uid}")
    public int delete(@Param("uid") int uid);

    @Select("select * from user limit #{from},#{pagesize}")
    public List<User> findByPage(@Param("from") int from, @Param("pagesize") int pagesize);

    @Update("update user set money = ifnull(money,0) + #{money} where uid = #{uid}")
    public int updateMoney(@Param("money") int money, @Param("uid") int uid);

}